package com.xinqi.modules.exam.paper.controller.inner;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.exam.paper.client.CourseExamPaperClient;
import com.xinqi.modules.exam.paper.dto.req.CourseExamPaperQueryDTO;
import com.xinqi.modules.exam.paper.dto.req.CourseExamPaperUpdateDTO;
import com.xinqi.modules.exam.paper.dto.rsp.CourseExamPaperResultDTO;
import com.xinqi.modules.exam.paper.service.CourseExamPaperService;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Primary;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


/**
 * 课程测评内部控制层
 *
 * @author: linkai
 * @date: 2023/07/02
 */
@Hidden
@Primary
@RestController
@RequiredArgsConstructor
public class CourseExamPaperInnerController implements CourseExamPaperClient {
    private final CourseExamPaperService courseExamPaperService;

    @Override
    public R<PageInfo<CourseExamPaperResultDTO>> page(CourseExamPaperQueryDTO dto) {
        PageInfo<CourseExamPaperResultDTO> page = courseExamPaperService.page(dto, dto);
        return R.data(page);
    }

    @Override
    public R<CourseExamPaperResultDTO> findById(Long id) {
        CourseExamPaperResultDTO dto = courseExamPaperService.findById(id);
        return R.data(dto);
    }

    /**
     * 修改课程测评
     */
    @Operation(summary = "修改课程测评")
    @PutMapping("/{id}")
    public R<Boolean> update(@PathVariable("id") Long id, @RequestBody CourseExamPaperUpdateDTO dto) {
        dto.setId(id);
        return R.data(courseExamPaperService.updateById(dto));
    }
}
